﻿using System;
using System.ComponentModel;
using System.Xml;
using System.Xml.Serialization;

namespace LaunchPad.Core
{
    public class EffectTrackEvent : TrackEvent
    {
        public EffectTrackEvent()
            : this(TimeSpan.Zero, TimeSpan.Zero, TimeSpan.FromSeconds(3)) { }

        public EffectTrackEvent(TimeSpan time, TimeSpan leadIn, TimeSpan leadOut) :
            base(time, leadIn, leadOut)
        {
        }

        private EffectTrack _effect;

        public void Initialize(Product product)
        {
            if (product != null)
            {
                LeadIn = product.LeadIn;
                LeadOut = product.LeadOut;
            }
        }

        [XmlIgnore]
        public bool IsOverridden
        {
            get
            {
                if (Effect.Product == null)
                    return false;
                return LeadIn != Effect.Product.LeadIn || LeadOut != Effect.Product.LeadOut;
            }
        }

        [XmlIgnore]
        public EffectTrack Effect
        {
            get { return _effect; }
            set
            {
                if (_effect != value)
                {
                    _effect = value;
                    OnPropertyChanged("Effect");
                    OnPropertyChanged("Description");
                }
            }
        }
    }
}
